#import <QuartzCore/QuartzCore.h>
#import "TTNeedTableViewController.h"
#import "TTNeedViewController.h"
#import "TTHelpView.h"
#import "NeedHelpsViewDataSource.h"
#import "NeedHelpsResultsModel.h"
#import "NeedHelpsModel.h"
#import "MenuController.h"


#import "INDefaultStylesheet.h"

static CGFloat kImageWidth = 57;
static CGFloat kImageHeight = 57;
static const CGFloat kSmallMargin = 6;


@implementation TTNeedViewController


@synthesize need_id, user_id, Helps;



///////////////////////////////////////////////////////////////////////////////////////////////////
// UIViewController

- (void)loadView {
	//[super loadView];
	self.statusBarStyle = UIStatusBarStyleBlackOpaque;
	self.navigationBarTintColor = TTSTYLEVAR(needishBlueColor);
	
	//self.hidesBottomBarWhenPushed = YES;
	UIScrollView* scrollView = [[[UIScrollView alloc] initWithFrame:TTNavigationFrame()] autorelease];
	scrollView.autoresizesSubviews = YES;
	scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
	scrollView.backgroundColor = [UIColor whiteColor];//	RGBCOLOR(216, 221, 231);
	self.view = scrollView;
	self.view.backgroundColor = [UIColor whiteColor];
	self.statusBarStyle = UIStatusBarStyleDefault; // IBUIStatusBarStyle
	
	NSString* remoteImage = @"http://profile.ak.fbcdn.net/v223/35/117/q223792_6978.jpg";		
	TTImageView* _imageView = [[[TTImageView alloc] initWithFrame:CGRectZero] autorelease];
	
	TTStyledTextLabel* label1 = [[[TTStyledTextLabel alloc] initWithFrame:CGRectZero] autorelease];

	_imageView.URL = remoteImage;
	
	
	
	CALayer * imglayer = [_imageView layer];
	[imglayer setMasksToBounds:YES];
	[imglayer setCornerRadius:10.0];
	[imglayer setBorderWidth:0.5];
	[imglayer setBorderColor:[TTSTYLEVAR(needPictureUrlBorderColor) CGColor]];
	
	
	//Label DisplayName
	label1.font = TTSTYLEVAR(needSubjectFont);
	
	label1.text = [TTStyledText textFromXHTML:user_id lineBreaks:YES URLs:YES];
//	label1.contentInset = UIEdgeInsetsMake(10, 10, 10, 10);
	label1.textColor = TTSTYLEVAR(needSubjectColor);
	label1.backgroundColor = [UIColor clearColor];
//	label1.fon
	[label1 sizeToFit];
	
	
	UIColor* black = RGBCOLOR(158, 163, 172);

	CGFloat padding = 8;
	CGFloat viewWidth = scrollView.width +2;
	CGFloat viewHeight = 80;

	CGFloat x = -1;
	CGFloat y = -1;
	
    CGRect frame = CGRectMake(x, y, viewWidth, viewHeight);
    TTView* view = [[[TTView alloc] initWithFrame:frame] autorelease];
    view.backgroundColor = scrollView.backgroundColor;
	view.style = [TTShapeStyle styleWithShape:[TTSpeechBubbleShape shapeWithRadius:0 pointLocation:305
																		  pointAngle:170
																		   pointSize:CGSizeMake(20,10)] next:
					[TTSolidFillStyle styleWithColor:RGBCOLOR(216, 221, 231) next:
					 [TTSolidBorderStyle styleWithColor:black width:1 next:nil]]];

	
	_imageView.frame = CGRectMake(padding, padding , kImageWidth, kImageHeight);
	label1.frame = CGRectMake(kImageWidth + padding*2 , 10, scrollView.width - kImageWidth - padding, label1.font.lineHeight);
						   
	
	[view addSubview:_imageView];	
	
	[view addSubview:label1];		

	
	[scrollView addSubview:view];
	
   // x += frame.size.width + padding;

	scrollView.contentSize = CGSizeMake(scrollView.width, y );
}

////////////////////////////////////////////////////////////////////////////////////
#pragma mark TTViewController

- (UIImage*)imageForError:(NSError*)error
{
    return [UIImage imageNamed:@"Three20.bundle/images/error.png"];
}


- (id)initWithNeed:(NSString*)need {
	self.hidesBottomBarWhenPushed = YES;
	
	TTLOG(@"initWithNeed: %@ ", need);
	if (self = [super init]) {
		self.need_id = need;
		self.title = @"Need";
		
		self.autoresizesForKeyboard = YES;
//		self.Helps = [[TTNeedTableViewController alloc] initWithNeed:need];

	}

	
	return self;
}


- (void)dealloc {
	[Helps dealloc];
    [super dealloc];
}


@end
